﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Example_SeoulOpenAPI.Services;

namespace Example_SeoulOpenAPI
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();
            StationService.StationDownloadCompleted += new StationService.StationsDownloadStatus(StationService_StationDownloadCompleted);
        }

        private void DownloadButton_Click(object sender, RoutedEventArgs e)
        {
            StationService.DownloadStationsByLineNumAsync("2");
        }

        void StationService_StationDownloadCompleted(
            Exception errorStatus, 
            System.Collections.ObjectModel.ObservableCollection<ViewModels.Station> stations)
        {
            StationListBox.ItemsSource = stations;
            if (errorStatus != null) MessageBox.Show("다운로드에 실패하였습니다: " + errorStatus.Message);
        }

        private void NaviButton_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/ArrivalInfoPage.xaml", UriKind.Relative));
        }

        private void NaviButton2_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/PassingInfoPage.xaml", UriKind.Relative));
        }

    }
}